﻿package rob.skin{
	import rob.data.RGB;
	import rob.data.Vect3d;
	import flash.display.Sprite;
	import rob.util.NumberUtil;
	
	public class ColourSkin{
		private var _colour:RGB;
		private var _hexColour:Number;
		
		public function ColourSkin(colour:RGB):void{
			_colour = colour;
			_hexColour = RGB.rgbToHex(colour);
		}
		
		public function setup():void{
			
		}
		
		// now also use normal for different shades...
		public function beginFill(mc:Sprite):void{
			
			with(mc.graphics){
				beginFill(_hexColour,1);
			}
		}
		
		// TODO: improve this
		public function applyLight(n:Vect3d){
			var kup:Number = (n.y >= 0) ? n.y : 0;
			var dp:Number = (80*kup + 20*Math.abs(n.x + n.z) + 30*Math.abs(n.x - n.z)+ 20)/255;
			//var dp:Number = (200 * n.y + 100)/225;
			dp = NumberUtil.constrain(dp,0,1);
			_hexColour = (_colour.r * dp) << 16 | (_colour.g * dp) << 8 | (_colour.b * dp);
		}
		
		public function get colour():Boolean{ return (_colour == 0) ? false : true;}
		
		public function toString():String{
			return "ColourSkin: " +name+"("+_textured+",["+_colour+"])";
		}
	}
}